<?php
App::import('Vendor', 'ajaxuploader/ajaxuploader');

class AjaxUploaderComponent extends Object {
var $components = array('Session');
// list of valid extensions, ex. array("jpeg", "xml", "bmp")
    var $_allowedExtensions = array("jpeg", "gif", "jpg", "bmp");
// max file size in bytes
    var $_sizeLimit = "";
    var $_upload_dir = "img/";

    function startup(&$controller) {
        $this->_sizeLimit = (10 * 1024 * 1024);
        $this->_upload_dir = WWW_ROOT . $this->_upload_dir;
    }

    function handleUpload() {
        $uploader = new qqFileUploader($this->_allowedExtensions, $this->_sizeLimit);
        $this->_upload_dir.=$_GET['upload_dir']."/";        
        $result = $uploader->handleUpload($this->_upload_dir,FALSE);        
        $this->Session->write($_GET['upload_dir'],$result['filename']);            
        return $result;
    }

}